//
//  RHHomeItemCell.m
//  RuiHeAppApp
//
//  Created by Jun on 2023/7/18.
//

#import "RHHomeItemCell.h"

@implementation RHHomeItemCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self setupUI];
    }
    return self;
}



- (void)setupUI{
        
    
    [self setBackgroundColor:UIColor.clearColor];
    [self.contentView setBackgroundColor:UIColor.clearColor];
    
    
    NSArray *titles = @[@"Credential",@"Cooperation"];
    NSArray *des = @[@"academic accreditation",@"win-win cooperation"];
    NSArray *images = @[@"home_item_l",@"home_item_r"];
    NSMutableArray *array = [NSMutableArray array];
    kWeakSelf;
    [images enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        UIImageView *view = [[UIImageView alloc] init];
        [view setImage:[UIImage imageNamed:obj]];
        [view.layer setCornerRadius:5];
        [self.contentView addSubview:view];
        [array addObject:view];
        
        QMUILabel *titleLab = [[QMUILabel alloc] init];
        [titleLab setText:titles[idx]];
        [titleLab setFont:[UIFont boldSystemFontOfSize:20]];
        [titleLab setTextAlignment:NSTextAlignmentLeft];
        [titleLab setTextColor:UIColor.whiteColor];
        [view addSubview:titleLab];
        
        QMUILabel *desLab = [[QMUILabel alloc] init];
        [desLab setText:des[idx]];
        [desLab setFont:[UIFont systemFontOfSize:14]];
        [desLab setTextAlignment:NSTextAlignmentLeft];
        [desLab setNumberOfLines:2];
        [desLab setTextColor:UIColor.whiteColor];
        [view addSubview:desLab];
        
        
        UITapGestureRecognizer *tapView = [[UITapGestureRecognizer alloc] init];
        view.userInteractionEnabled = YES;
        [view addGestureRecognizer:tapView];
        
        [tapView.rac_gestureSignal subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
            if(weakSelf.itemActionBlock){
                weakSelf.itemActionBlock(idx);
            }
        }];
        
        [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(15);
            make.top.mas_offset(15);
            make.right.mas_offset(-15);
            make.height.mas_equalTo(20);
        }];
        
        [desLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(titleLab);
            make.top.equalTo(titleLab.mas_bottom).offset(5);
            make.bottom.mas_equalTo(-15);
            
        }];
    }];
    
    
    [array mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(10);
        make.bottom.mas_offset(-10);
        make.height.mas_equalTo(100);
    }];
    
    [array mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:10 leadSpacing:15 tailSpacing:15];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}

@end
